<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

   
    <input type="text" name="username">
    <br><br>
    <input type="password" name="userpwd">
    <br><br>
    <button>登录</button>


    <script>

        const oBtn = document.querySelector('button') ;
        const oUser = document.querySelector('input[type="text"]') ;
        const oPwd = document.querySelector('input[type="password"]') ;


        // get请求中，前端通过 接口路径后面拼接? 来实现参数的携带



        oBtn.onclick = function() {
            // 验证

            const username = oUser.values ; 
            const userpwd = oPwd.value ;
            // if(username && userpwd) {

                // 请求   前端需要携带数据

                const xhr = new XMLHttpRequest() ; 
                xhr.open('get' , '../php/03get.php' + '?' + `username=${username}&userpwd=${userpwd}` , true) ;
                xhr.send() ;
                xhr.onreadystatechange = function() {
                    if(xhr.readyState === 4 && xhr.status === 200) {
                        const data = xhr.responseText ;
                        console.log(data);
                    }
                }

            // }
        }

    </script>
    
</body>
</html>